<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

    private $data = array();

    public function  __construct() {
        parent::__construct();

        //Load Helper and library
        $this->load->helper("url");
        $this->load->library("ci_smarty");
        $this->load->helper("text"); 
        $this->data['base_url'] = base_url();
        $this->data['root_url'] = $this->config->item('root_url');
        
        //$this->output->enable_profiler(TRUE);
        //Load Model
        $this->load->Model("admin/Mlogin");
    }

    function index() {
        $this->show_login(false);
    }

    public function login_user() {
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        if( $username && $password && $this->Mlogin->validate_user($username,$password)) {
            redirect(base_url()."admin/list-book.html"); 
        } else {
            $this->show_login(true);
        }
    }

    public function show_login( $show_error = false ) {
        $this->data['error'] = $show_error;
        $this->ci_smarty->view('backend/login.tpl',$this->data);
    }

    public function logout_user() {
    	$this->session->unset_userdata('username');
    	$this->session->unset_userdata('password');
    	$this->session->unset_userdata('name');
      	$this->session->sess_destroy();
      	redirect(base_url()."admin"); 
    }
}
    